package com.neusoft.SPNursingHome.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.SPNursingHome.po.*;
import com.neusoft.SPNursingHome.service.MealSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/mealSet")
public class MealSetController {

    @Autowired
    private MealSetService service;

    @GetMapping("/list")
    public ResponseBean<List<MealSet>> listAll() {
        return service.listAll();
    }

    @GetMapping("/listWithClient")
    public ResponseBean<IPage<MealSetWithClient>> listWithClient(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer adId,
            @RequestParam(required = false) String role,
            @RequestParam(defaultValue = "1") long page,
    @RequestParam(defaultValue = "10") long size) {
        return service.listAllWithClientName(name,adId,role,page,size);
    }

    @GetMapping("/listClientsWithoutMealSet")
    public ResponseBean<List<Client>> listClientsWithoutMealSet(
            @RequestParam(required = false) String name) {
        return service.listClientsWithoutMealSet(name);
    }

    @GetMapping("/{id}")
    public ResponseBean<MealSet> getById(@PathVariable Integer id) {
        return service.getById(id);
    }

    @PostMapping("/create")
    public ResponseBean<Void> create(@RequestBody MealSet set) {
        return service.create(set);
    }

    @PutMapping("/update")
    public ResponseBean<Void> update(@RequestBody MealSet set) {
        return service.update(set);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean<Void> delete(@PathVariable Integer id) {
        return service.deleteById(id);
    }

    @GetMapping("/search/{name}")
    public ResponseBean<List<MealSet>> search(@PathVariable String name) {
        return service.searchByClientName(name);
    }
}
